package com.zy.nft_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.nft_system.domain.Result;
import com.zy.nft_system.domain.User;
import com.zy.nft_system.domain.dto.UserDto;
import com.zy.nft_system.domain.dto.UserInfo;
import com.zy.nft_system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.MultipartFilter;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description: TODO
 * @date 2022/9/28 12:35
 */
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/regist")
    public Result regist(@RequestBody User user){
        log.info("用户正在进行注册");
        //用户注册
        return userService.regist(user);
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpServletRequest request){
        log.info("用户正在进行登录");
        //用户登录
        return userService.login(user, request);
    }
    @PostMapping("/loginOut")
    public Result loginOut(@RequestBody User user, HttpServletRequest request){
        log.info("用户正在退出");
        return userService.loginOut(user,request);
    }
    @GetMapping("/userInfo")
    public Result userInfo(int id){
        log.info("正在查寻用户id为{}的信息",id);
        return userService.userInfo(id);
    }
    @PutMapping("/setUserInfo")
    public Result setUserInfo(@RequestBody User user){
        log.info("用户{}正在修改用户信息",user.getName());
        return userService.setUserInfo(user);
    }
    @PutMapping("/setUserPwd")
    public Result setUserPwd(@RequestBody UserDto userDto, HttpServletRequest request){
        log.info("用户{}正在修改用户信息",userDto.getName());
        return userService.setUserPwd(userDto,request);
    }
    @PostMapping("/setUserImg")
    public Result setUserImg(MultipartFile file,String name){
        log.info("用户正在修改头像");
        return userService.setUserImg(file,name);
    }
    @GetMapping("/queryUserList")
    public Result queryUserList(String name, String iphone, Integer status){
        log.info("正在查询全部用户信息");
        //有模糊查询的效果
        return userService.queryUserList(name,iphone,status);
    }
    @PostMapping("/uploadUserImg")
    public Result uploadUserImg(MultipartFile file){
        log.info("用户正在上传用户头像");
        return userService.uploadUserImg(file);
    }
    @PostMapping("/insertUser")
    public Result insertUser(@RequestBody UserInfo userInfo){
        log.info("正在插入用户");
        return userService.insertUser(userInfo);
    }
    @GetMapping("/queryUser")
    public Result queryUser(int id){
        log.info("正在查询用户信息");
        return userService.queryUser(id);
    }
    @GetMapping("/deleteUser")
    public Result deleteUser(int id){
        log.info("正在更具id删除用户信息");
        return userService.deleteUser(id);
    }
    @PutMapping("/updateUserInfo")
    public Result updateUserInfo(@RequestBody UserInfo userInfo){
        log.info("正在更具id修改用户信息");
        return userService.updateUserInfo(userInfo);
    }
    @PutMapping("/updateUserStatus")
    public Result updateUserStatus(@RequestBody UserInfo userInfo){
        log.info("正在更具id修改用户状态信息");
        return userService.updateUserStatus(userInfo);
    }
    @GetMapping("/queryUserByid")
    public Result queryUserByid(Integer id){
        log.info("正在更具id查询用户信息");
       return userService.queryUser(id);
    }
    @GetMapping("/text")
    public Result text(){
        return Result.error("测试拦截器");
    }

    @GetMapping("/queryManageUser")
    public Result queryManageUser(boolean emil){
        log.info("正在查询管理员用户信息");

        return userService.queryManageUser(emil);
    }
}
